default_platform(:android)

platform :android do
  before_all do
    reset_git_repo(force: true, skip_clean: true)
  end

  desc "Debug Build"
    lane :app_build_dev do |options|
      commit = last_git_commit

      gradle(task: "clean")
      gradle(task: "assembleCiDebug", flags: "--stacktrace --no-daemon")

      firebase_app_distribution(
        app: "1:308085819273:android:1b039e927925b879a00358",
        service_credentials_file: "service-account.json",
        release_notes: "Author: #{commit[:author]}, changes: #{commit[:message]}",
        groups: "horsysteam",
        apk_path: "app/build/outputs/apk/ci/debug/app-ci-debug.apk"
      )
  end

  desc "Debug Build (F-Droid)"
    lane :app_build_fdroid do |options|
      commit = last_git_commit

      gradle(task: "clean")
      gradle(task: "assembleFdroidCiDebug", flags: "--stacktrace --no-daemon")

      firebase_app_distribution(
        app: "1:308085819273:android:3c060bb15aa35d79a00358",
        service_credentials_file: "service-account.json",
        release_notes: "F-Droid Build - Author: #{commit[:author]}, changes: #{commit[:message]}",
        groups: "horsysteam",
        apk_path: "app/build/outputs/apk/fdroidCi/debug/app-fdroidCi-debug.apk"
      )
    end

  desc "Release Build"
    lane :app_build_release do |options|
      commit = last_git_commit

      gradle(task: "clean")
      gradle(task: "assembleCiRelease", flags: "--stacktrace --no-daemon")

      firebase_app_distribution(
        app: "1:308085819273:android:d1451c165f07056ea00358",
        service_credentials_file: "service-account.json",
        release_notes: "Author: #{commit[:author]}, changes: #{commit[:message]}",
        groups: "horsysteam",
        apk_path: "app/build/outputs/apk/ci/release/app-ci-release.apk"
      )
  end

end
